/**
 * Description:该类主要用于创建一个标签
 * Copyright: 成都和为科技有限公司 2012
 */

function RadioButtonGroup() {}

RadioButtonGroup.inherit(Container);

/**
 * 初始化方法
 * @param {Object} g_sPath
 * @param {Object} sName 控件名称
 * @param {Object} obj	控件html对象	
 * @param {Object} parent 父控件
 * @param {Object} oAttr 属性对象
 */
RadioButtonGroup.prototype.init = function () {
	RadioButtonGroup.base.init.call(this);
}

RadioButtonGroup.prototype.create = function() {
    this._html = document.createElement("div");
    $(this._html).addClass("radio");
}

RadioButtonGroup.prototype.initLoad = function() {
	RadioButtonGroup.base.initLoad.call(this);
	var othis = this;
    $("input", this.getHTML()).bind("change", function(e){
        othis.triggerAttributeEvent("onchange");
    });
}

/**
 * 获取当前控件的值。需要提交到数据库
 */
RadioButtonGroup.prototype.getValue = function(){
	var value= $("input:checked", this._html).val(); 
	if(!value) value = "";
	return value;
}
/**
 * 获得错误消息
 */
RadioButtonGroup.prototype.getError = function(){
    return this._error;
}
/**
 * 设置错误消息
 */
RadioButtonGroup.prototype.setError = function(sError){
    this._error = sError;
    this._tiptext = sError;
}
/**
 * 显示错误
 */
RadioButtonGroup.prototype.showError = function(tip) {
    if (!this.isValidate()) {
        $(this.getHTML()).addClass("has-error");
        this._tiptext = this.getError();
        if (typeof(tip)  == "undefined" || tip == true) {
//        	var scrollTop = this.getHTML().scrollTop;
            var scrollTop = $(this.getHTML()).offset().top - 100;

            $("body").animate({scrollTop:scrollTop}, 500);

            WinUtil.showTip(this.getHTML(), {title:this._tiptext,
                placement:"bottom"});
        }
    } else {
        this._tiptext = "";
        $(this.getHTML()).removeClass("has-error");
    }
}
/**
 * 设置值
 * @param {} sValue
 */
RadioButtonGroup.prototype.setValue = function(sValue) {
	if (!sValue || sValue == "") {
		this.clearSelect();
	}
	$("input[value = " + sValue + "]",this._html).each(function(){
		this.checked = true;
	});
}

RadioButtonGroup.prototype.clearSelect = function() {
	$("input", this._html).each(function(){
		this.checked = false;
	});
}

/**
 * 设置为可编辑
 */
RadioButtonGroup.prototype.setEnable = function() {
    $("input",this._html).each(function(){
        this.disabled = false;
    });
	this._disable = false;
}

/**
 * 设置为只读
 */
RadioButtonGroup.prototype.setDisable = function(){
	$("input",this._html).attr("disabled", "true");
	this._disable = true;
}